package demo2;

import java.util.Arrays;

/*class Person_ implements Cloneable {
    public String name;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Person_(String name) {
        this.name = name;
    }
}*/

class Money implements Cloneable{
    public double money = 12.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person_ implements Cloneable{
    public String name;
    public Money m;
    public Person_(String name) {
        this.name = name;
        m = new Money();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //return super.clone();
        Person_ tmp = (Person_) super.clone();
        tmp.m = (Money) this.m.clone();

        return tmp;
    }
}
public class Test2 {
    public static void main(String[] args)throws CloneNotSupportedException  {
        Person_ person1 = new Person_("zhangsan");
        Person_ person2 = (Person_) person1.clone();
        System.out.println("修改之前："+person1.m.money);//12.5
        System.out.println("修改之前："+person2.m.money);//12.5
        person2.m.money = 99.99;

        System.out.println("修改之后："+person1.m.money);// 12.5
        System.out.println("修改之后："+person2.m.money);// 99.99
    }
   /* public static void main1(String[] args) throws CloneNotSupportedException{
        Person_ person1 = new Person_("zhangsan");
        Person_ person2 = (Person_) person1.clone();
        System.out.println(person2.name);
    }*/
}
